/*
 * Copyright (C) 2008-2013 www.pretty-tools.com
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

var yrprxUtil = {};

yrprxUtil.isArray = function (obj)
{
    return obj.constructor.toString().indexOf("function Array()") == 0;
}

yrprxUtil.isString = function (obj)
{
    return typeof(obj)=='string'
}

yrprxUtil.trim = function(str)
{
    return str ? str.replace(/^\s+|\s+$/g, '') : null;
}

yrprxUtil.defaultIfEmpty = function(str, def)
{
    try
    {
        return str && str.length > 0 ? str : def;
    }
    catch(ex)
    {
        return def;
    }
}

yrprxUtil.isLocalFileURL = function(url)
{
    return url && 0 == url.indexOf("file://");
}

yrprxUtil.convertStringToDate = function (dateString)
{
    if (!dateString || !dateString.length)
        return null;

    return new Date(dateString);
}

yrprxUtil.convertStringToTime = function (dateString)
{
    var date = this.convertStringToDate(dateString);

    return date ? date.getTime() : 0;
}

yrprxUtil.convertTimeToString = function (time)
{
    return time ? new Date(time).toString() : null;
}
